package BIll;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import Dao.DAORoom_user;
import Entity.Room_user;
import Entity.User;
import tool.DaoFactory;

public class BLLRoom_user extends BLLAbstract{
	private DaoFactory daoFactory = DaoFactory.getDaoFactory();
	private DAORoom_user daoRoomUser = daoFactory.getInstance(DAORoom_user.class);
	
	
	public boolean addRoomUser(String idcard,int roomid,String starttime,int day){
		Room_user roomUser = new Room_user();
		roomUser.setIdcard(idcard);
		roomUser.setRoomid(roomid);
		roomUser.setStarttime(starttime);
		roomUser.setStatus(1);
		roomUser.setDay(day);
		boolean b = daoRoomUser.addRoomUser(roomUser);
		return b;
	}
	
	public Map<String, Object> queryUserByRoomid(int roomid){
		Map<String, Object> map = daoRoomUser.queryUserByRoomid(roomid);
		return map;
	}
	

	public int checkOut(int roomid){
		SimpleDateFormat simpleDateFormat =  new SimpleDateFormat("yyyy.MM.dd");
		Date date =new Date();
		String leavetime = simpleDateFormat.format(date);
		int day = daoRoomUser.checkOut(roomid,leavetime);
		return day;
	}
}
